package com.yurun.controller.admin;

import com.yurun.entity.VisitLog;
import com.yurun.model.dto.VisitLogUuidTime;
import com.yurun.model.vo.Result;
import com.yurun.service.VisitLogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/admin")
public class VisitLogController {
    @Autowired
    VisitLogService visitLogService;
    /**
     * @Description: 添加访问日志
     * @Param: visitLog
     * @return: void
     * @Author: JimmyYao
     * @Date: 2022/2/9
     */
    @PostMapping("/visitlog")
    public Result addVisitLog(@RequestBody VisitLog visitLog){
        visitLogService.addVisitLog(visitLog);
        return Result.ok("添加访问日志成功");
    }
    /**
     * @Description: 通过ID-删除访问日志
     * @Param: id
     * @return: void
     * @Author: JimmyYao
     * @Date: 2022/2/9
     */
    @DeleteMapping("/visitlog/id")
    public Result deleteVisitLogById(@RequestParam Long id){
        visitLogService.deleteVisitLogById(id);
        return Result.ok("删除访问日志成功");
    }
    /**
     * @Description: 通过访客标识和日期-获取访问日志
     * @Param: uuid
     * @Param startDate
     * @Param endDate
     * @return: com.yurun.model.vo.Result
     * @Author: JimmyYao
     * @Date: 2022/2/9
     */
    @GetMapping("/visitlog/uuid/date")
    public Result getVisitLogListByUUIDAndDate(@RequestParam String uuid,
                                               @RequestParam String startDate,
                                               @RequestParam String endDate){
        List<VisitLog> object=visitLogService.getVisitLogListByUUIDAndDate(uuid, startDate, endDate);
        return Result.ok("查询访问日志成功",object);
    }
    /**
     * @Description: 获取昨日访客标识和创建时间
     * @Param:
     * @return: com.yurun.model.vo.Result
     * @Author: JimmyYao
     * @Date: 2022/2/9
     */
    @GetMapping("/UuidAndCreatetime")
    public Result getUUIDAndCreateTimeByYesterday(){
        List<VisitLogUuidTime> object=visitLogService.getUUIDAndCreateTimeByYesterday();
        return Result.ok("查询访客标识和创建时间成功",object);
    }
    /**
     * @Description: 查询今日访问数量
     * @Param:
     * @return: com.yurun.model.vo.Result
     * @Author: JimmyYao
     * @Date: 2022/2/9
     */
    @GetMapping("/visitlognumber")
    public Result countVisitLogByToday(){
        int object=visitLogService.countVisitLogByToday();
        return Result.ok("查询今日访问日志成功",object);
    }
}
